<?php
// 下线专题
namespace Beerus\Modules\DesignerFinder\Actions;

use Doraemon\model\DesignerFinder\Subject;
use Encore\Admin\Admin;
use Illuminate\Http\Request;
use Encore\Admin\Actions\RowAction;

class Online extends RowAction {
    public $name = '上线';

    public function handle($iSubjectId) {
        $aSubjectInfo = Subject::getSubjectInfoById($iSubjectId);
        if (empty($aSubjectInfo['qr_code'])) {
            return $this->response()->error('私域微信二维码未配置')->refresh();
        }
        if (($cnt = Subject::countOnlineSubject()) >= 3) {
            return $this->response()->error('仅允许上线'.$cnt.'个专题')->refresh();
        }
        if (!Subject::onlineSubject($iSubjectId)) {
            return $this->response()->error('上线失败')->refresh();
        }
        return $this->response()->success('上线成功')->refresh();
    }

    public function retrieveModel(Request $request) {
        if (!$key = $request->get('_key')) {
            return false;
        }
        return $key;
    }
}
